function [handles]=WriteTrajIndivDbl(handles,sortedScoredObjectsToProcess,ObjectsInFrame,lastFrameTrajAppeared,TrajObjNum,frameToConsider,PredictedObject,BaseObject,params)


TrajMask=~imread(params.maskfilenames{lastFrameTrajAppeared},'tif');
ObjectsInTrajMask = regionprops(bwconncomp(TrajMask,4),'PixelIdxList','PixelList');
rgbTrajMask=uint16(TrajMask);

for i=1:length(ObjectsInTrajMask)
    if(i==TrajObjNum)
        rgbTrajMask(ObjectsInTrajMask(i).PixelIdxList)=2;
    else
        rgbTrajMask(ObjectsInTrajMask(i).PixelIdxList)=1;
    end
end

rgbTrajMaskLabel=label2rgb(rgbTrajMask,'hsv','k','shuffle');

transMask=logical(false(size(TrajMask)));
origMask=uint16(zeros(size(TrajMask)));

%Process scored mask
ObjectMask=~imread(params.maskfilenames{frameToConsider},'tif');
ObjectsInObjectMask = regionprops(bwconncomp(ObjectMask,4),'PixelIdxList');
rgbObjectMask=uint16(ObjectMask);
[m n]=size(sortedScoredObjectsToProcess);

for j=1:m
    rgbObjectMask(ObjectsInObjectMask(sortedScoredObjectsToProcess(j,params.CP.object)).PixelIdxList)=...
        10/(sortedScoredObjectsToProcess(j,params.CP.score));
end

rgb2=label2rgb(rgbObjectMask,'jet','k');

%Plot translated Objects    
displacement=PredictedObject(params.ON.CentroidX:params.ON.CentroidY)-BaseObject(params.ON.CentroidX:params.ON.CentroidY);
u=displacement(1);
v=displacement(2);

PredictedPixelList(:,1)=max(round(ObjectsInTrajMask(TrajObjNum).PixelList(:,1)+u),1);
PredictedPixelList(:,2)=max(round(ObjectsInTrajMask(TrajObjNum).PixelList(:,2)+v),1);

for i=1:size(PredictedPixelList,1)
    transMask(PredictedPixelList(i,2),PredictedPixelList(i,1))=1;
end
transRgb=label2rgb(transMask,'hsv','k','shuffle');
 
%plots the location of the original object
origMask(ObjectsInTrajMask(TrajObjNum).PixelIdxList)=2;
origMaskRgb=label2rgb(origMask,'hsv','k');
 
if(isempty(handles.plotFigure))
    handles.plotFigure=figure;
    handles.image_handle=imshow(rgbTrajMaskLabel,'InitialMagnification','fit');
    handles.scroll_panel=imscrollpanel(handles.plotFigure,handles.image_handle);
    
    
    impixelinfo(handles.image_handle);
    imoverview(handles.image_handle)
    api = iptgetapi(handles.scroll_panel);
    api.setMagnificationAndCenter(1,BaseObject(params.ON.CentroidX),BaseObject(params.ON.CentroidY));
    %prevents the image from being erased when cla is called to clear text
    %from axis
    set(handles.image_handle,'HandleVisibility','off')
    figure(handles.plotFigure);
    
    handles.plotFigure2=figure;
    handles.image_handle2=imshow(rgb2,'InitialMagnification','fit'); 
    hold on
    handles.image_handle3 = imshow(transRgb,'InitialMagnification','fit');
    set(handles.image_handle3, 'AlphaData', 0.3);
    handles.image_handle4 = imshow(origMaskRgb,'InitialMagnification','fit');
    set(handles.image_handle4, 'AlphaData', 0.3);
    
%     handles.scroll_panel2=imscrollpanel(handles.plotFigure2,handles.image_handle3);
%     %handles.hMagBox = immagbox(handles.plotFigure,handles.image_handle);
%     %hpanel = imoverviewpanel(handles.scroll_panel,handles.image_handle);
%     impixelinfo(handles.image_handle2);
%     imoverview(handles.image_handle2)
%     api = iptgetapi(handles.scroll_panel2);
%     api.setMagnificationAndCenter(1,BaseObject.Centroid(1),BaseObject.Centroid(2));
%     %prevents the image from being erased when cla is called to clear text
%     %from axis
%     set(handles.image_handle,'HandleVisibility','off')

    figure(handles.plotFigure2);
    for j=1:m
       
        Centroid=ObjectsInFrame(sortedScoredObjectsToProcess(j,params.CP.object),params.ON.CentroidX:params.ON.CentroidY);
        FormattedScore=sprintf('%0.1f',sortedScoredObjectsToProcess(j,params.CP.score));
        text(Centroid(1),Centroid(2),FormattedScore,'Color','w');
    end
    
else
    %Clears the current axis of the text from previous calls to this
    %function
    %     figure(handles.plotFigure);
    %     cla
    %     api = iptgetapi(handles.scroll_panel);
    %     loc = api.getVisibleLocation();
    %     mag = api.getMagnification();
    %     api.replaceImage(rgb);
    %     api.setMagnification(mag);
    %     api.setVisibleLocation(loc);
    
end


 